import axios from "axios"
import pinia from "@/stores/index"
import { ElMessage } from "element-plus"

const servicea = axios.create({
	baseURL: "https://www.dance365.com/apis/",
	timeout: 50000,
})
servicea.interceptors.request.use((config: any) => {
	return config
})

servicea.interceptors.response.use(
	async (response) => {
		const res = response.data

		return res
	},
	(error) => {
		if (error.message.indexOf("timeout") != -1) {
			ElMessage.error("网络超时")
		} else if (error.message == "Network Error") {
			ElMessage.error("网络连接错误")
		} else {
			if (error.response.data) ElMessage.error(error.response.statusText)
			else ElMessage.error("接口路径找不到")
		}
		return Promise.reject(error)
	}
)

export default servicea

// 李潇成的 》》》
import { reqHomeBannerBack } from "./types/lxcTypes"

let homeServe = axios.create({
	baseURL: "https://www.dance365.com/apis/",
})
homeServe.interceptors.request.use((config) => {
	//此处可以携带统一的请求头
	//此处可以设置统一的超时
	return config
})
homeServe.interceptors.response.use((response) => {
	//此处可以对响应的数据做一个是否请求成功的判断
	//此处可以对响应的数据做一个简化
	return response.data
})

export const reqHomeBanner = () =>
	homeServe.get<any, reqHomeBannerBack>(
		"/moment/moments/rec/default?access_token=c494ae44-3adc-48ca-8749-5128a53358d7&column=recommend&pageSize=20&pageNum=0&localCache=0",
		// "moment/moments/rec/default?access_token=c494ae44-3adc-48ca-8749-5128a53358d7&column=recommend&pageSize=20&pageNum=0&localCache=0",
		{
			params: {},
		}
	)

	export const reqSortList = () =>
	homeServe.get(
		// "/moment/moments/rec/default?access_token=c494ae44-3adc-48ca-8749-5128a53358d7&column=recommend&pageSize=20&pageNum=5&localCache=100",
		"moment/moments/rec/default?access_token=c494ae44-3adc-48ca-8749-5128a53358d7&column=recommend&pageSize=20&pageNum=50&localCache=0",
		{
			params: {},
		}
	)


let homeServeDia = axios.create({
	baseURL: "https://www.dance365.com/apis/",
})
export const reqInterest = (num: number = 0) => {
	return homeServeDia.get<any, any>(
		`avocation/avocations/rec/user?access_token=c494ae44-3adc-48ca-8749-5128a53358d7&pageNum=${num}&pageSize=20`,
		{
			params: {},
		}
	)
}
homeServeDia.interceptors.request.use((config) => {
	return config
})
homeServeDia.interceptors.response.use((res) => {
	return res
})
// https://www.dance365.com/apis/moment/moments/rec/default?access_token=c494ae44-3adc-48ca-8749-5128a53358d7&column=recommend&pageSize=20&pageNum=0&localCache=0

// 配置新建一个 axios 实例
const service = axios.create({
	baseURL: "/api",
	timeout: 3000,
})

// 添加请求拦截器
service.interceptors.request.use(
	(config) => {
		return config
	},
	(err) => {
		Promise.reject(err)
	}
)

//响应拦截器
service.interceptors.response.use(
	(res) => {
		return res.data
	},
	(err) => {
		Promise.reject(err)
	}
)

// export default service
